package com.tubang.organization.util;


import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.tubang.component.entity.UserEntity;

/**
 * 目前没有启用
 * @ClassName PasswordHelper 
 * @Description TODO
 * @author wsl 
 * @date 2017年12月13日 下午1:51:10
 */
public class PasswordHelper {
	//private RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
	private static String algorithmName = "md5";
	private static Integer hashIterations = 2;

	public static void encryptPassword(UserEntity user) {
		//String salt=randomNumberGenerator.nextBytes().toHex();
		String newPassword = new SimpleHash(algorithmName, user.getPassword(), ByteSource.Util.bytes(user.getMobile()),
				hashIterations).toHex();
		//String newPassword = new SimpleHash(algorithmName, user.getPassword()).toHex();
		user.setPassword(newPassword);

	}
	
	/**
	 * 
	 * @Title getNewPassword 
	 * @Description TODO
	 * @param  username 用户名=登录手机号
	 * @param  password 密码
	 * @param  设定文件 
	 * @return String 返回类型  加密后的密码
	 * @throws
	 */
	public static String getNewPassword(String username, String password) {
		return new SimpleHash(algorithmName, password, ByteSource.Util.bytes(username), hashIterations).toHex();
	}
	
	
	
	public static void main(String[] args) {
		String newPassword = PasswordHelper.getNewPassword("13663529688","123456");
		System.out.println(newPassword);
		
	}
}
